import router from './router/index.ts'
import NProgress from 'nprogress'
import settings from './settings'
const whiteList = ["/login"]

document.title = settings.title
router.beforeEach((to, from, next) => {
    NProgress.start()
    if (localStorage.getItem('token')){
        if (to.path === '/login'){
            next("/")
            NProgress.done()
        } else if (whiteList.indexOf(to.path) !== -1){
            next()
        } else {
            next()
        }
    } else {
        // 没有token
        if (whiteList.indexOf(to.path) !== -1){
            // 白名单的随便进
            next()
        }else {
            next("/login")
            NProgress.done()
        }
    }
})


router.afterEach(() => {
    NProgress.done()
})

